﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNETVN.PORTAL.Components.Configuration.Items;
using ASPNETVN.PORTAL.Components.Security;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Components.Configuration.Settings;
using ASPNETVN.PORTAL.Components.UI.DataTypes;
using ASPNETVN.PORTAL.Components.Configuration;

namespace ASPNETVN.PORTAL.Modules.SHORTCUT
{
    public partial class Main : PortalModuleControl
    {
        public Main()
        {
            ModuleSettingItem itemSetting = new ModuleSettingItem(new StringDataType());
            itemSetting.Value = Guid.Empty.ToString();
            itemSetting.Name = "ModuleID của Module ";
            itemSetting.Description = "ModuleID của Module";
            itemSetting.SortOrder = 1;
            this.BaseSettings.Add("SHORTCUT.ModuleID", itemSetting);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (PortalSecurity.IsInRole("1") == false)
            {
                Guid moduleID = new Guid(this.Settings["SHORTCUT.ModuleID"].ToString());
                Guid tabID = Guid.Empty;
                PortalDataSet ds = PortalConfiguration.GetPortalDataSet();

                foreach (PortalDataSet.TabRow tab in ds.Tab.Rows)
                {
                    if (tab.PortalID == Global.PortalID)
                    {
                        foreach (PortalDataSet.ModuleRow moduleRow in tab.GetModuleRows())
                        {
                            if (moduleRow.ID == moduleID)
                            {
                                //Load Portal Module Control.
                                PortalModuleControl portalModuleControl = (PortalModuleControl)Page.LoadControl( moduleRow.ModuleDefinitionRow.SourceFile);
                                portalModuleControl.Module = Module.LoadModuleRow(moduleRow);
                                this.Container.Controls.Add(portalModuleControl);
                                //Set Portal ID
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
}